import org.junit.Before;
import org.junit.Test;

import java.io.BufferedReader;
import java.io.PrintStream;

import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertThat;
import static org.mockito.Matchers.anyString;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

/**
 * Created with IntelliJ IDEA.
 * User: Thoughtworker
 * Date: 10/10/13
 * Time: 1:27 PM
 * To change this template use File | Settings | File Templates.
 */
public class MenuTests {
    private PrintStream printStream;
    private BufferedReader bufferReader;
    private MainMenu menu;

    @Before
    public void setUp() throws Exception {
        printStream = mock(PrintStream.class);
        bufferReader = mock(BufferedReader.class);
        menu = new MainMenu(printStream, bufferReader);

    }


    @Test
    public void shouldListNamesOfAllPlayersWithCoaches(){
        menu.printListOfAllPlayers();
        verify(printStream).print( "Alex Team 1 Micheal Pay Head Coach Charlie Assistant Coach  0 6\nBill Team 2 Jimmy Jones Head Coach  1 18\n"
                );
    }


    @Test
    public void shouldReadMenuOption() throws Exception {
        when(bufferReader.readLine()).thenReturn("1");
        assertThat(menu.readUserInput(), is("1"));

    }

    @Test
    public void shouldPrintMenuOptions() throws Exception {
        menu.printMenuOptions();
        verify(printStream).print(anyString());
    }


    @Test
    public void findAParticularPlayerByName() throws Exception {
        when(bufferReader.readLine()).thenReturn("Bill");
        menu.invokeOptionSelected(2);
        verify(printStream).println("Player Found");
    }
}
